package com.hghivln.controller.system;

import com.hghivln.aspectj.annotation.Log;
import com.hghivln.aspectj.enums.BusinessType;
import com.hghivln.pojo.dto.NoticeDto;
import com.hghivln.pojo.vo.AjaxResult;
import com.hghivln.service.NoticeService;
import com.hghivln.utils.ShiroUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.NotEmpty;

@RestController
@RequestMapping("system/notice")
public class NoticeController {

    @Autowired
    private NoticeService noticeService;

    /**
     * 分页查询
     */
    @GetMapping("listNoticeForPage")
    public AjaxResult listNoticeForPage(NoticeDto noticeDto) {
        return noticeService.listNoticeForPage(noticeDto);
    }


    /**
     * 添加
     */
    @PostMapping("addNotice")
    @Log(title = "添加通知",businessType = BusinessType.INSERT)
    public AjaxResult addNotice(@Validated NoticeDto noticeDto) {
        noticeDto.setSimpleUser(ShiroUtils.getCurrentSimpleUser());
        return noticeService.addNotice(noticeDto);
    }

    /**
     * 修改
     */
    @PutMapping("updateNotice")
    @Log(title = "修改通知",businessType = BusinessType.UPDATE)
    public AjaxResult updateNotice(@Validated NoticeDto noticeDto) {
        noticeDto.setSimpleUser(ShiroUtils.getCurrentSimpleUser());
        return noticeService.updateNotice(noticeDto);
    }

    /**
     * 删除
     */
    @DeleteMapping("deleteNoticeByIds/{ids}")
    @Log(title = "删除通知",businessType = BusinessType.DELETE)
    public AjaxResult deleteNoticeByIds(@PathVariable @Validated @NotEmpty(message = "要删除的通知ID不能为空")Long[] ids) {
        return noticeService.deleteNoticeByIds(ids);
    }

    /**
     * 根据ID查询一个通知信息
     */
    @GetMapping("getNoticeById/{id}")
    public AjaxResult getNoticeById(@PathVariable @Validated @NotEmpty(message = "通知ID不能为空") Long id) {
        return noticeService.getNoticeById(id);
    }

}
